import java.lang.reflect.Field;

/**
 * @author zhu
 * @date 2024-04-01
 */
public class Woman<P extends Animal>{
    private P pet;

    public P getPet() {
        return pet;
    }

    public void setPet(P pet) {
        this.pet = pet;
    }

    public Woman() {
    }

    public Woman(P pet) {
        this.pet = pet;
    }
    public void DaZhaoHu(){
        // 1.获取宠物对象的 Class 对象
        Class<?> clazz = pet.getClass();

        // 2.获取宠物的姓名
        try {
            Field nameFiled = clazz.getDeclaredField("name");
            nameFiled.setAccessible(true);
            Object name = nameFiled.get(pet);
            System.out.println("某女主人带着" + name + "逛街...");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
